import time

from selenium.webdriver.common.by import By

from common.Utils import ForumDriver
#测试帖子编辑页面
class ForumEdit:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://127.0.0.1:9580/index.html"
        self.driver = ForumDriver.driver
        self.driver.get(self.url)

    #正确发布帖子（登陆状态下）
    def EditSucTestByLogin(self):
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        #测试标题输入框
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_title")
        #测试内容输入框
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll")
        #测试“发布”摁钮
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit")

        #添加标题
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("自动化测试创建")
        #找到编辑区域，输入关键词(编辑区域不可操作）
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.editormd-toolbar > div > ul > li:nth-child(4)").click()
        #直接点击发布按钮来发布博客
        #self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        #屏幕截图验证编辑成功
        ForumDriver.getScreeShot()

    #异常发布帖子（登录状态下）
    def EditFailTestByLogin(self):
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        # 测试标题输入框
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title")
        # 测试内容输入框
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll")
        # 测试“发布”摁钮
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit")

        #不添加标题
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.editormd-toolbar > div > ul > li:nth-child(4)").click()
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        alert=self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div")
        print(alert.text)

        #不添加内容
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("自动化测试创建")
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        alert = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")
        print(alert.text)